package com.shaozi.nc.manage.secretary;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.shaozi.lib.manage.ManageBase;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.nc.data.model.AttendanceDateInitSyncModel;
import com.shaozi.nc.data.mongodao.AttendanceMDao;

/**
 * 考勤 获取实例：(AttendanceManage) BeanUtils.getBean("attendanceManage");
 * 
 * @author xueshuwu
 *
 */
public class AttendanceManage extends ManageBase {
	@Autowired
	private AttendanceMDao attendanceMDao;

	public AttendanceManage() {

	}

	public void save(String companyId, AttendanceDateInitSyncModel model) throws SzException {
		attendanceMDao.save(companyId, model);
	}

	/**
	 * 是否今天成功初使化
	 * 
	 * @param companyId
	 * @return
	 * @throws SzException
	 */
	public boolean isTodaySuccInit(String companyId) throws SzException {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		long dateBegin = cal.getTimeInMillis();
		List<AttendanceDateInitSyncModel> models = attendanceMDao.getDateSync(companyId, dateBegin, 1);
		if ((models == null) || (models.isEmpty()))
			return false;
		for (AttendanceDateInitSyncModel model : models) {
			if (model.getIsSucc() == 1)
				return true;
		}
		return false;
	}

}
